<include file="Public/header"/>

<div id="app">
    <!-- sidebar -->
    <include file="Public/left"/>
    <!-- / sidebar -->
    <div class="app-content">
        <!-- start: TOP NAVBAR -->
        <include file="Public/headernav"/>
        <!-- end: TOP NAVBAR -->
        <div class="main-content">
            <div class="wrap-content container" id="container">
                <!-- start: PAGE TITLE -->
                <section id="page-title">
                    <div class="row">
                        <div class="col-sm-8 col-md-offset-5">
                            <h1 class="mainTitle">{$msgtitle}</h1>
                            <span class="mainDescription">&nbsp;&nbsp;代理编辑</span>
                        </div>

                    </div>
                </section>
                <!-- end: PAGE TITLE -->
                <!-- start: YOUR CONTENT HERE -->
                <div class="container-fluid container-fullw bg-white">
                    <form action="" role="form" id="form2" novalidate="novalidate" method="post">
                        <div class="row">
                            <div class="col-md-6 col-md-offset-3">
                                <div class="form-group">
                                    <label class="control-label">
                                        用户 <span class="symbol required" aria-required="true"></span>
                                    </label>
                                    <input type="text" placeholder="选择用户" class="form-control"
                                           value="{$data.member_card}"
                                           id="member_card" readonly>
                                    <input type="hidden" value="{$data.member_id}" id="member_id" name="member_id">
                                </div>

                                <div class="form-group">
                                    <label class="control-label">
                                        省份 <span class="symbol required" aria-required="true"></span>
                                    </label>
                                    <select class="form-control" name="provinceid" id="province">
                                        <option value="">请选择</option>
                                        <volist name="province" id="vo">
                                            <option value="{$vo.cityid}"
                                            <if condition="$vo['cityid'] eq $data['provinceid']">selected</if>
                                            >{$vo.cityname}</option>
                                        </volist>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">
                                        城市 <span class="symbol required" aria-required="true"></span>
                                    </label>
                                    <select class="form-control" name="cityid" id="city">
                                        <if condition="empty($data['cityid'])">
                                            <option value="">请选择</option>
                                            <else/>
                                            <option value="{$data.cityid}">{$data.city}</option>
                                        </if>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">
                                        区县 <span class="symbol required" aria-required="true"></span>
                                    </label>
                                    <select class="form-control" name="areaid" id="area">
                                        <if condition="empty($data['cityid'])">
                                            <option value="">请选择</option>
                                            <else/>
                                            <option value="{$data['areaid']}">{$data.area}</option>
                                        </if>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">
                                        返点比例(%) <span class="symbol required" aria-required="true"></span>
                                    </label>

                                    <div class="input-group col-md-3">
                                        <input type="text" name="rate" value="{$data['rate']*100}" id="rate"
                                               placeholder="返点比例" class="form-control">
                                        <span class="input-group-addon">%</span>
                                    </div>
                                </div>
                                <div class="form-group ">
                                    <label class="control-label">
                                        状态 <span></span>
                                    </label>

                                    <div class="clip-radio radio-primary fa-hover Primary">
                                        <if condition="$data.id gt 0">
                                            <input type="radio" value="1" name="status" id="id_no"
                                            <if condition="$data.status eq 1">checked="checked"</if>
                                            >
                                            <label for="id_no">
                                                有效
                                            </label>
                                            <input type="radio" value="0" name="status" id="id_yes"
                                            <if condition="$data.status eq 0">checked="checked"</if>
                                            >
                                            <label for="id_yes">
                                                无效
                                            </label>
                                            <else/>
                                            <input type="radio" value="1" name="status" id="id_no" checked="checked">
                                            <label for="id_no">
                                                有效
                                            </label>
                                            <input type="radio" value="0" name="status" id="id_yes">
                                            <label for="id_yes">
                                                无效
                                            </label>
                                        </if>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-4 col-md-offset-5">
                                <input type="hidden" value="{$data.id}" name="id">
                                <button class="btn btn-primary btn-wide pull-left" type="submit">
                                    提交 <i class="fa fa-arrow-circle-right"></i>
                                </button>
                            </div>
                            <div class="col-md-8">
                                <p>

                                </p>
                            </div>

                        </div>
                    </form>
                </div>


                <!-- end: YOUR CONTENT HERE -->
            </div>
        </div>
    </div>
    <!--  FOOTER and SETTINGS -->

    <include file="Public/footer"/>
    <!-- end: FOOTER -->
    <!-- start: OFF-SIDEBAR -->

    <!-- end: OFF-SIDEBAR -->

</div>
<!-- start: MAIN JAVASCRIPTS -->

<include file="Public/javascript"/>

<!-- end: CLIP-TWO JAVASCRIPTS -->

<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<script src="__PUBLIC__/bootstrap/vendor/ckeditor/ckeditor.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/ckeditor/adapters/jquery.js"></script>
<script src="__PUBLIC__/bootstrap/vendor/jquery-validation/jquery.validate.min.js"></script>
<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY -->
<!-- start: CLIP-TWO JAVASCRIPTS -->
<!-- <script src="__PUBLIC__/bootstrap/assets/js/main.js"></script> -->
<!-- start: JavaScript Event Handlers for this page -->
<!--<script src="__PUBLIC__/bootstrap/assets/js/form-validation.js"></script>-->
<script>
    /*选择代理用户弹窗*/
    $('#member_card').click(function () {
        layer.open({
            type: 2,
            title: '选择用户',
            shadeClose: true,
            shade: 0.8,
            area: ['70%', '90%'],
            content: '{:U("admin/agent/popup_user")}'
        });
    });
    /*代理区域三级联动*/
    $('#province').change(function () {
        var provinceid = $('#province').val();
        var city = 'city';
        get_city(city, provinceid);
    });
    $('#city').change(function () {
        var provinceid = $('#province').val();
        var cityid = $('#city').val();
        var city = 'area';
        get_city(city, provinceid, cityid);
    })
    function get_city(city, provinceid, cityid) {
        if (cityid) {
            var data = {provinceid: provinceid, cityid: cityid};
        } else {
            var data = {provinceid: provinceid};
        }
        $.ajax({
            url: '{:U("admin/agent/get_city")}',
            data: data,
            type: 'post',
            dataType: 'json',
            success: function (data) {
                var city_msg = '<option value="">请选择</option>';
                $('#area').html(city_msg);
                $.each(data, function () {
                    city_msg += '<option value="' + this.cityid + '">' + this.cityname + '</option>';
                })
                $('#' + city).empty();
                $('#' + city).append(city_msg);
            }
        });
    };
    /*表单验证*/
    $().ready(function () {
        $("#form2").validate({
            rules: {
                member_id: "required",
                areaid: {
                    required: true,
                    remote: {
                        url: '{:U("admin/agent/check_exist_agent")}',
                        type: 'post',
                        dataType: 'json',
                        data: {
                            areaid: function () {
                                return $("#area").val();  //去验证数据
                            },
                            id:function(){
                                return "{$_GET['id']}";
                            },
                            member_id:function(){
                                return $('#member_id').val();
                            }
                        },
                        dataFilter: function (msg) {　　　　//判断控制器返回的内容
                            if (msg == '1') {
                                return false;
                            } else {
                                return true;
                            }
                        }
                    }
                },
                rate: {
                    required: true,
                    max: 99.9999,
                    min: 0,
                    number: true
                }
            },
            messages: {
                member_id: "请输入员工姓名",
                areaid: {
                    required: '请选择代理区域',
                    remote: '该区域已存在代理'
                },
                rate: {
                    required: '请输入返点比例',
                    max: '不能超过100',
                    min: '请输入正确的数值',
                    number: '请输入正确的数值'
                }
            }
        });
    });
</script>
<!-- end: JavaScript Event Handlers for this page -->
</body>
</html>
